﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System.Windows;
using System.Windows.Input;

namespace EventWindowHandler.Plugin
{
    /// <summary>
    /// Interaction logic for EventInfoWindow.xaml
    /// </summary>
    public partial class EventInfoWindow : Window
    {
        public static readonly DependencyProperty RecordedEventInfoViewModelProperty =
            DependencyProperty.Register("RecordedEventInfoViewModel", typeof(RecordedEventInfoViewModel), typeof(EventInfoWindow), new PropertyMetadata(null, OnRecordedEventInfoViewModelPropertyChanged));

        public RecordedEventInfoViewModel RecordedEventInfoViewModel
        {
            get { return (RecordedEventInfoViewModel)GetValue(RecordedEventInfoViewModelProperty); }
            set { SetValue(RecordedEventInfoViewModelProperty, value); }
        }

        private static void OnRecordedEventInfoViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EventInfoWindow source = d as EventInfoWindow;
            source.UpdateRecordedEventInfoViewModel(e.NewValue as RecordedEventInfoViewModel);
        }

        private void UpdateRecordedEventInfoViewModel(RecordedEventInfoViewModel infoViewModel)
        {
            RecordedEventInfoViewModel = infoViewModel;

            // Let the UI bind to the view-model.
            this.DataContext = RecordedEventInfoViewModel;            
        }

        public EventInfoWindow()
        {
            InitializeComponent();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
                e.Handled = true;
            }
        }
    }
}
